package kz.pompei.OneGwt.client.personrole.impl;

import kz.pompei.OneGwt.client.personrole.RoleListView;
import kz.pompei.OneGwt.cmodel.SimpleRecord;
import kz.pompei.OneGwt.ifaces.widget.ButtonWidget;
import kz.pompei.OneGwt.ifaces.widget.ListWidget;
import kz.pompei.OneGwt.ifaces.widget.NullAdapters;
import kz.pompei.OneGwt.ifaces.widget.StateMessage;
import kz.pompei.OneGwt.ifaces.widget.gwtadapters.Button_impl_ButtonWidget;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class RoleListViewImpl implements RoleListView {
  private ListWidget<SimpleRecord> listLeft = NullAdapters.noListWidget();
  private ListWidget<SimpleRecord> listRight = NullAdapters.noListWidget();
  private ListWidget<SimpleRecord> comboApplication = NullAdapters.noListWidget();
  private ButtonWidget buttonToRight = NullAdapters.noButton();
  private ButtonWidget buttonToLeft = NullAdapters.noButton();
  
  private Widget containerUI = null;
  
  public Widget getContainerUI() {
    if (containerUI == null) return containerUI = createContainerUI();
    return containerUI;
  }
  
  private Widget createContainerUI() {
    VerticalPanel wall = new VerticalPanel();
    wall.setSpacing( 5 );
    wall.setWidth( "100%" );
    wall.setHeight( "100%" );
    {
      HorizontalPanel top = new HorizontalPanel();
      wall.add( top );
      wall.setCellHeight( top, "1" );
      {
        HTML html = new HTML( "Приложение:" );
        html.addStyleName( "one-TextBoxLabel" );
        top.add( html );
      }
      {
        ListBox combo = new ListBox();
        combo.setWidth( "100%" );
        combo.setHeight( "100%" );
        combo.addItem( "asd1" );
        combo.addItem( "asd2" );
        top.add( combo );
        top.setCellWidth( combo, "100%" );
        top.setCellHeight( combo, "100%" );
        
        comboApplication = new SimpleListWidget( combo );
      }
    }
    {
      HorizontalPanel lists = new HorizontalPanel();
      lists.setHeight( "100%" );
      lists.setWidth( "100%" );
      wall.add( lists );
      wall.setCellHeight( lists, "100%" );
      {
        ListBox left = new ListBox();
        left.setVisibleItemCount( 13 );
        left.setWidth( "100%" );
        left.setHeight( "100%" );
        lists.add( left );
        lists.setCellWidth( left, "50%" );
        lists.setCellHeight( left, "100%" );
        
        listLeft = new SimpleListWidget( left ) {
          @Override
          protected String whatUserMessageText(StateMessage stateMessage) {
            switch (stateMessage) {
            case USER1:
              return "<Выберите приложение>";
              
            case USER2:
              return "<Выберите пользователя>";
            }
            return super.whatUserMessageText( stateMessage );
          }
        };
      }
      {
        VerticalPanel btns = new VerticalPanel();
        btns.setSpacing( 5 );
        lists.add( btns );
        {
          HTML x = new HTML( "&nbsp;&nbsp;" );
          btns.add( x );
        }
        {
          Button b = new Button( "<-" );
          btns.add( b );
          
          buttonToLeft = new Button_impl_ButtonWidget( b );
        }
        {
          Button b = new Button( "->" );
          btns.add( b );
          
          buttonToRight = new Button_impl_ButtonWidget( b );
        }
      }
      {
        ListBox right = new ListBox();
        right.setVisibleItemCount( 13 );
        right.setWidth( "100%" );
        right.setHeight( "100%" );
        lists.add( right );
        lists.setCellWidth( right, "50%" );
        lists.setCellHeight( right, "100%" );
        
        listRight = new SimpleListWidget( right ) {
          @Override
          protected String whatUserMessageText(StateMessage stateMessage) {
            switch (stateMessage) {
            case USER1:
              return "<Выберите приложение>";
              
            case USER2:
              return "<Выберите пользователя>";
            }
            return super.whatUserMessageText( stateMessage );
          }
        };
      }
    }
    return wall;
  }
  
  @Override
  public ListWidget<SimpleRecord> listLeft() {
    return listLeft;
  }
  
  @Override
  public ListWidget<SimpleRecord> listRight() {
    return listRight;
  }
  
  @Override
  public ListWidget<SimpleRecord> comboApplication() {
    return comboApplication;
  }
  
  @Override
  public ButtonWidget buttonToRight() {
    return buttonToRight;
  }
  
  @Override
  public ButtonWidget buttonToLeft() {
    return buttonToLeft;
  }
}
